import {
	request,

} from './request'

export function Login(mobile, password) {
	return request({
		url: "/user/v1/login",
		method: "post",
		data: {
			mobile,
			password
		}
	})
}
export function Register(mobile, username, password) {
	return request({
		url: "/user/v1/register",
		method: "post",
		data: {
			mobile,
			username,
			password
		}
	})
}

export function GinaSmsCode(mobile) {
	return request({
		url: "/user/v1/gain_sm_code",
		method: "get",
		params: {
			mobile,
		}
	})
}
// 短信登录
export function LoginSmsCode(query = {}) {
	return request({
		url: '/user/v1/sm_code_login',
		method: 'post',
		data: {
			"mobile": query.mobile,
			"code": query.code
		}
	})

}
// 用户信息
export function UserInfo() {
	return request({
		url: "/user/v1/userinfo",
		method: "get",
		headers: {
			Authorization: localStorage.getItem("token")
		}
	})
}

// 更新用户数据
export function UpdateUser(formData, query={}) {
	return request({
		url: "/user/v1/userupdata",
		method: 'put',
		headers: {
			Authorization: localStorage.getItem("token"),
			"Content-Type": "multipart/form-data"
		},

		data: formData,
		params: { username :query.username},
	})
}

export function AddStorage(query = {}) {
	console.log(query)
	return request({
		url: '/bucket/v1/createbucket',
		method: 'post',
		data: {
			access_key: query.access_key,
			secret_key: query.secret_key,
			bucket_name: query.bucket_name,
			alias: query.alias,
			zone: query.zone,
			domain_name: query.domain_name

		}
	})
}

export function ListBuckets(Limit, Page) {
	return request({
		url: "/bucket/v1/list",
		method: "get",

		params: {
			limit: Limit,
			page: Page
		}
	})
}

// 存储空间详情查看
export function Tickets(bucket_id) {
	return request({
		url: "/bucket/v1/detail",
		method: "get",

		params: {
			bucket_id,
		}
	})
}

// 存储空间删除
export function IsDelete(id, bucketname) {
	return request({
		url: "/bucket/v1/del",
		method: "delete",
		params: {
			id,
			bucketname,
		}
	})
}

/**目录相关 */
//首页数据
export function HomeCatalogue() {
	return request({
		url: "/catalogue/v1/home_catalogue",
		method: "get",
	})
}
// 请求所有
// export function CatalogueLists(limit, page, bucket_id) {
// 	return request({
// 		url: "/catalogue/v1/list",
// 		method: "get",
// 		params: {
// 			limit,
// 			page,
// 			bucket_id
// 		}

// 	})
// }
// 创建
export function CatalogueCreate(query = {}) {
	return request({
		url: "/catalogue/v1/create",
		method: "post",

		data: {
			catalogue_name: query.catalogue_name,
			bucket_id: query.bucket_id,
			bucket_name: query.bucket_name
		}
	})
}

// 删除
export function CatalogueDel(query = {}) {

	return request({
		url: "/catalogue/v1/delete",
		method: "delete",
		data: {
			bucket_name: query.bucket_name,
			bucket_id: query.bucket_id,
			catalogue_name: query.catalogue_name,
		}

	})
}

// 详情
export function CatalogueDetail(query = {}) {
	return request({
		url: "/catalogue/v1/detail",
		method: "get",
		params: {
			bucket_name: query.bucket_name,
			bucket_id: query.bucket_id,
			catalogue_id: query.catalogue_id,
			catalogue_name: query.catalogue_name,
		}

	})
}


/**
 * 文件相关接口
 */


//  加载当前选择网盘里的所有文件
export function FilesAll(bucketname, rootdir, bucketid, limit, page) {

	return request({
		url: '/v1/files/all',
		method: "get",

		params: {
			bucketname,
			rootdir,
			bucketid,
			limit,
			page

		}
	})
}
// 上传文件
export function FileUpload(formData, query = {}) {
	return request({
		url: '/file/v1/uploadchunk',
		method: 'put',
		headers: {
			"Content-Type": "multipart/form-data"
		},

		data: formData,
		timeout: 0,
		params: {
			bucket_id: query.bucket_id,
			bucket_name: query.bucket_name,
			catalogue_id: query.catalogue_id,
			catalogue_name: query.catalogue_name
		}
	})
}

export function MegerChunks(hash, fileName, query = {}) {
	return request({
		url: '/file/v1/megerchunk',
		method: 'get',
		timeout: 0,
		params: {
			hash,
			fileName,
			bucket_id: query.bucket_id,
			bucket_name: query.bucket_name,
			catalogue_id: query.catalogue_id,
			catalogue_name: query.catalogue_name
		}
	})
}



// 文件搜索
export function SearchFiles(object_name, catalogue_name, bucket_name, limit, page) {
	return request({
		url: '/file/v1/objectsearch',
		method: 'get',

		params: {
			object_name,
			catalogue_name,
			bucket_name,
			limit,
			page
		}
	})
}


/* 文件删除 */
export function FileDel(bucket_name, catalogue_name, object_name) {
	return request({
		url: '/file/v1/objectdelete',
		method: 'delete',
		params: {
			bucket_name,
			catalogue_name,
			object_name
		}

	})
}

export function ObjectAll(bucket_name, catalogue_name, limit, page) {
	return request({
		url: '/file/v1/objectlists',
		method: 'get',


		params: {
			bucket_name,
			catalogue_name,
			limit,
			page
		}

	})
}

/**下载 */
export function DownloadFile(id, bucketname, cataloguename) {
	return request({
		url: '/file/v1/download',
		method: 'get',
		responseType: 'blob',

		params: {
			id,
			bucketname,
			cataloguename,

		}

	})
}

// 历史记录
export function HistoryAll(limit, page) {
	return request({
		url: '/history/v1/info',
		method: 'get',


		params: {
			limit,
			page
		}

	})
}

/**文件创建分享 */
export function ShareFile(query = {}) {
	return request({
		url: '/share/v1/create_share',
		method: 'post',
		data: {
			bucket_name: query.bucket_name,
			catalogue_name: query.catalogue_name,
			expiration: query.expiration,
			object_name: query.object_name
		}
	})
}
/**
 * 加载所有分享数据
 */

export function ShareLists(limit, page) {
	return request({
		url: '/share/v1/list_share',
		method: 'get',
		params: {
			limit,
			page
		}
	})
}

/**
 * 轮播图
 */

//  添加轮播图
export function CarouselAdd(formData, sort) {
	return request({
		url: '/admin/v1/carousel/create',
		method: 'put',
		headers: {
			"Content-Type": "multipart/form-data"
		},
		data: formData,
		params: { sort },

	})
}



//  加载所有轮播图
export function CarouselLists() {
	return request({
		url: '/admin/v1/carousel/list',
		method: 'get',

	})
}

//  更新轮播图
export function CarouselUpdate(formData, id) {
	return request({
		url: '/admin/v1/carousel/update',
		method: 'put',
		headers: {
			"Content-Type": "multipart/form-data"
		},
		data: formData,
		params: {
			id: id,

		}
	})
}

//  删除轮播图
export function CarouseDelete(id) {
	return request({
		url: '/admin/v1/carousel/delete',
		method: 'delete',
		params: {
			id: id,
		}
	})
}